package main

import (
	"fmt"
	"strconv"
	"strings"
)

/*
func Contains(s, substr string) bool 字符串s中是否包含substr，返回bool值
func Join(a []string, sep string) string 字符串链接，把slice a通过sep链接起来
func Index(s, sep string) int 在字符串s中查找sep所在的位置，返回位置值，找不到返回-1
func Repeat(s string, count int) string 重复s字符串count次，最后返回重复的字符串
func Replace(s, old, new string, n int) string 在s字符串中，把old字符串替换为new字符串，n表示替换的次数，小于0表示全部替换
func Split(s, sep string) []string 把s字符串按照sep分割，返回slice
func Trim(s string, cutset string) string 在s字符串的头部和尾部去除cutset指定的字符串
func Fields(s string) []string 去除s字符串的空格符，并且按照空格分割返回slice
字符串转化的函数在strconv中，如下也只是列出一些常用的：
Format 系列函数把其他类型的转换为字符串
*/

func testString() {
	fmt.Println(strings.Contains("welcome to Shenzhen,gd", "henzhen"))
	fmt.Println(strings.Contains("welcome to Shenzhen,gd", "guangzhou"))

	s := []string{"foo", "bar", "baz"}
	fmt.Println(strings.Join(s, ","))

	fmt.Println(strings.Index("welcome to Shenzhen,gd", "gd"))
	fmt.Println(strings.Index("welcome to Shenzhen,gd", "guangdong"))

	fmt.Println("ba" + strings.Repeat("na", 2))
	fmt.Println(strings.Replace("welcome to Shenzhen,gd,Shenzhen", "Shenzhen", "Guangzhou", 1))
	fmt.Println(strings.Replace("welcome to Shenzhen,gd,Shenzhen", "Shenzhen", "Guangzhou", 2))
	fmt.Println(strings.Replace("welcome to Shenzhen,gd,Shenzhen", "Shenzhen", "Guangzhou", -1))

	fmt.Printf("%q\n", strings.Split("nice,to,meet,you,!", ","))

	fmt.Printf("[%q]\n", strings.Trim(" !!! good !!! ", " "))
	fmt.Printf("[%q]\n", strings.Trim(" !!! good !!! ", "! "))

	fmt.Printf("Fields are: %q\n", strings.Fields("nice to meet you"))

	str := make([]byte, 0, 100)
	str = strconv.AppendInt(str, 1234, 10)
	str = strconv.AppendBool(str, true)
	str = strconv.AppendQuote(str, "abcdefg")
	str = strconv.AppendQuoteRune(str, '行')
	fmt.Println(str)
	fmt.Println(string(str))

	a := strconv.FormatBool(false)
	b := strconv.FormatFloat(123.456, 'g', 12, 64)
	c := strconv.FormatInt(1234, 10)
	d := strconv.FormatUint(123456, 10)
	e := strconv.Itoa(1024)
	fmt.Println(a, b, c, d, e)

	a1, err := strconv.ParseBool("true")
	checkErr(err)
	b1, err := strconv.ParseFloat("123.23", 64)
	checkErr(err)
	c1, err := strconv.ParseInt("1234", 10, 64)
	checkErr(err)
	d1, err := strconv.ParseUint("12323", 10, 64)
	checkErr(err)
	e1, err := strconv.Atoi("1233")
	checkErr(err)
	fmt.Println(a1, b1, c1, d1, e1)
}

func checkErr(e error) {
	if e != nil {
		fmt.Println(e)
	}
}

func main() {
	testString()
}
